package com.yjhb.android.sbz.mvp.login;

import com.yjhb.android.sbz.entity.UserInfo;
import com.yjhb.android.sbz.http.HttpObserver;
import com.yjhb.android.sbz.http.HttpTool;
import com.jojo.android.zxlib.tool.ZxDeviceTool;
import com.jojo.android.zxlib.tool.ZxEncodeTool;

/**
 * 创建者 zx
 * 创建时间 2020/11/23 16:37
 */
public class WxLoginPresenter extends LoginPresenter<WxLoginView> {
    private final String TAG = "WxLoginPresenter";

    public WxLoginPresenter(WxLoginView wxLoginView) {
        super(wxLoginView);
    }

    @Override
    protected void onDestroy() {

    }

    /**
     * 微信登录
     *
     * @param code
     */
    public void wxLogin(String code, String parentId, String device) {
        if (view != null) {
            view.loggingIn();
        }
        HttpTool.request(model.wxLogin(ZxEncodeTool.urlEncode(ZxDeviceTool.getPhoneDetail(),"UTF-8"), code, parentId, device), new HttpObserver<UserInfo>() {
            @Override
            public void onResult(UserInfo data) {
                if (view != null) {
                    view.onLoginSuccess(data);
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view != null) {
                    view.onFailure(code, msg);
                }
            }
        });
    }

}
